package me.xue.communityhealth.service;

import me.xue.communityhealth.exception.ObjectNotFoundException;
import me.xue.communityhealth.model.Disease;
import me.xue.communityhealth.repo.DiseaseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiseaseService implements BaseService<Disease, Integer> {

    private final DiseaseRepository diseaseRepository;

    @Autowired
    public DiseaseService(DiseaseRepository diseaseRepository) {
        this.diseaseRepository = diseaseRepository;
    }

    @Override
    public int save(Disease disease) {
        return diseaseRepository.save(disease);
    }

    @Override
    public int update(Disease disease) {
        return diseaseRepository.update(disease);
    }

    @Override
    public int delete(Integer which) {
        return diseaseRepository.delete(which);
    }

    @Override
    public List<Disease> findAll() {
        return diseaseRepository.findAll();
    }

    public Disease findOne(Integer id) {
        Disease disease = diseaseRepository.findOne(id);
        if (disease == null) {
            throw new ObjectNotFoundException();
        }
        return disease;
    }

}
